package edu.kaifadui.lmbase.utils;

import edu.kaifadui.lmbase.vo.Result;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

import java.sql.ResultSet;

/**
 * @author 陈世杰
 * @date 2022/2/23 13:56
 * @email dualseason@qq.com
 */
public class Verification {
    public static String SendVerification(String target) throws EmailException {
        Email email = new SimpleEmail();
        int code = (int) ((Math.random() * 9 + 1) * 100000);
        email.setHostName("smtp.qq.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("2315363424@qq.com", "mczwenemcpwrdhji"));
        email.setSSLOnConnect(true);
        email.setFrom("2315363424@qq.com");
        email.setSubject("岭梦开发队系统通知中心");
        StringBuilder msgInfo = new StringBuilder();
        msgInfo.append("验证码如下 : ").append("\r\n\t");
        msgInfo.append(code).append("\r\n\t");
        email.setMsg(msgInfo.toString());
        email.addTo(target);
        email.send();
        return String.valueOf(code);
    }
}
